unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TFormMain = class(TForm)
    CheckBoxUp: TCheckBox;
    CheckBoxLow: TCheckBox;
    CheckBoxNum: TCheckBox;
    CheckBoxSpec: TCheckBox;
    EditLen: TEdit;
    LabelLen: TLabel;
    Label1: TLabel;
    EditCount: TEdit;
    ButtonGen: TButton;
    PageControlMain: TPageControl;
    TabSheetResult: TTabSheet;
    MemoResult: TMemo;
    TabSheetLog: TTabSheet;
    MemoLog: TMemo;
    EditFix: TEdit;
    LabelFix: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure ButtonGenClick(Sender: TObject);
  private
    { Private declarations }
    function GetRandStr(len : Integer; lowercase : Boolean = True;
      num : Boolean = True; uppercase : Boolean = False;Spec : Boolean=False) : string;
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.FormCreate(Sender: TObject);
begin
  PageControlMain.ActivePageIndex := 0;
    
end;

function TFormMain.GetRandStr(len : Integer; lowercase : Boolean = True;
num : Boolean = True; uppercase : Boolean = False;Spec : Boolean=False) : string;
const
  upperStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  lowerStr = 'abcdefghijklmnopqrstuvwxyz';
  numStr = '0123456789';
  specStr = '!#$%&*+-=?@^_~';
var
  sourceStr : string;
  i : Integer;
begin
  sourceStr := '';
  Result := '';
  if uppercase = True then
    sourceStr := sourceStr + upperStr;
  if lowercase = True then
    sourceStr := sourceStr + lowerStr;
  if num = True then
    sourceStr := sourceStr + numStr;
  if Spec = True then
    sourceStr := sourceStr + specStr;

  if (sourceStr = '') or (len<1) then
    exit;

  Randomize;
  for i:=1 to len do
  begin
    Result := Result + sourceStr[Random(Length(sourceStr)-1)+1];
  end;
end;


procedure TFormMain.ButtonGenClick(Sender: TObject);
var
  iCount,i : Integer;
  sStr : String;
begin
  MemoResult.Clear;

  iCount := StrToIntDef(EditCount.Text,5);

  for i := 0 to  iCount - 1 do
  begin
    sStr := GetRandStr(StrToIntDef(EditLen.Text,8),CheckBoxLow.Checked,CheckBoxNum.Checked,CheckBoxUp.Checked,CheckBoxSpec.Checked);
    sStr := Trim(EditFix.Text) + sStr;
    MemoResult.Lines.Add(sStr);

    sStr := Format('%s %s',[FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz',Now),sStr  ]);
    MemoLog.Lines.Add(sStr);
  end;


end;

end.
